package com.aaa.controller.scl;

import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.mht.TestResultMht;
import com.aaa.entity.scl.TestResultScl;
import com.aaa.entity.scl.ViewTestResultScl;
import com.aaa.service.scl.ViewTestResultSclService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultMht)表控制层
 *
 * @author makejava
 * @since 2022-09-05 19:41:05
 */
@RestController
@RequestMapping("viewTestResultScl")
public class ViewTestResultSclController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultSclService viewTestResultSclService;

    //查询所有
    @RequestMapping(value = "/queryAll.do")
    public Result queryAll(PageSortEntity pageSortEntity, ViewTestResultScl viewTestResultScl) {
        Page page = viewTestResultSclService.queryByPage(pageSortEntity, viewTestResultScl);
        return success(page.getResult(), page.getTotal());
    }

    //查询单个返回测试结果
    @RequestMapping(method = RequestMethod.POST, value = "queryAllById.do")
    public Result queryResultById(ViewTestResultScl viewTestResultScl) {
        List<ViewTestResultScl> viewTestResultScls = viewTestResultSclService.queryAllById(viewTestResultScl);
        ViewTestResultScl viewTestResultScl1 = viewTestResultScls.get(0);
        return success(viewTestResultScl1);
    }

    //查询返回测试结果给前端呈现echr图
    @RequestMapping(method = RequestMethod.POST, value = "queryResultToReport.do")
    public Result queryResultToReport() {
        Map map = viewTestResultSclService.queryResultToReport();
        return success(map);
    }

    /**
     * @param
     * @return
     * @description: 删除
     */
    @LogMonitor
    @RequestMapping("delete.do")
    public Result delete(int[] id) {

        boolean b = viewTestResultSclService.deleteById(id);
        boolean Id = viewTestResultSclService.deleteByTesterId(id);
        if (b && Id) {
            return success("删除成功");
        }
        return fail("删除失败");
    }
    //查询测试结果到查看详情
    @RequestMapping(method = RequestMethod.GET, value = "queryTestResultById.do")
    public Result queryTestResultById(PageSortEntity pageSortEntity, TestResultScl testResultScl){
        Page page = viewTestResultSclService.queryTestResultById(pageSortEntity, testResultScl);
        return success(page.getResult(),page.getTotal());
    }

}

